export var name = "category";

export function Render() {
    return `

<style>
   
html {
    font-size: 70%; 
}


@media screen and (min-width: 375px) and (max-width: 414px) {
    html {
        font-size: calc(11.5px + 1.8 * ((100vw - 375px) / 39)); /* 针对375-414px宽度精细调整 */
    }
}

@media screen and (min-width: 768px) {
    html {
        font-size: 13px;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    padding-top: 6rem;
    padding-bottom: 7rem;
    min-height: 100vh;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    padding: 1.4rem 0;
    border-bottom: 0.1rem solid #eee;
    z-index: 1000;
}

.header-left {
    position: absolute;
    left: 2.2rem;
    display: flex;
    align-items: center;
}

.back-btn,
.menu-btn {
    background: none;
    border: none;
    font-size: 2.2rem; 
    cursor: pointer;
    margin-right: 1.4rem;
    color: #000;
}

.title {
    font-size: 3rem; 
    font-weight: bold;
}

.main-content {
    display: flex;
    height: calc(100vh - 13rem);
}

.category-nav {
    width: 25%; 
    background-color: #f1f1f1;
    border-right: 0.1rem solid #eee;
    overflow-y: auto;
}

.category-nav ul {
    list-style: none;
}

.category-nav a {
    text-decoration: none;
    color: inherit;
    display: inline-block;
    width: 100%;
    height: 100%;
    text-align: center;
    line-height: 8rem;
}

.category-nav li {
    height: 8rem; 
    cursor: pointer;
    border-bottom: none;
    text-align: center;
    background-color: #f1f1f1;
    font-size:3rem; 
    margin-bottom: 2rem;
}

.category-nav .active {
    background-color: #ffffff;
    font-weight: bold;
    color: #000;
}

.product-display {
    width: 75%; /* 布局不变 */
    padding: 1.9rem;
    padding: 1.9rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: #fff;
}

.banner {
    margin-bottom: 1.9rem;
    border-radius: 0.9rem;
    overflow: hidden;
}

.banner img {
    width: 100%;
    height: auto;
    display: block;
}

.category-section {
    margin-bottom: 3.2rem;
    background-color: #fff;
    padding: 1.9rem;
    border-radius: 0.9rem;
    box-shadow: none;
}

.section-title {
    font-size: 2.8rem; 
    margin-bottom: 4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-more {
    font-size: 2.0rem;
    color: #999;
    text-decoration: none;
}

.product-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.3rem;
}

.product-item {
    width: calc(33.333% - 0.9rem); 
    text-align: center;
    margin-bottom: 1.9rem;
}

.product-item img {
    width: 100%;
    height: auto;
    border-radius: 0.7rem;
    margin-bottom: 1.1rem;
    display: block;
}

.product-item p {
    font-size: 2.5rem; /* 商品名称放大 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.8rem;
    letter-spacing: 0.07rem;
    font-weight: 480;
}

.footer-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 1.3rem 0;
    border-top: 0.1rem solid #eee;
    z-index: 1000;
    background-color: rgb(2, 103, 52);
    height: 6rem; /* 适度增高 */
}

.nav-item {
    text-align: center;
    cursor: pointer;
    flex: 1;
}

.nav-item img {
    width: 3rem; 
    height: 3rem;
    margin-bottom: 0.4rem;
}

.nav-item p {
    font-size: 1.5rem; /* 底部文字放大 */
    color: white;
}

/* 保持原有响应式布局 */
@media (max-width: 768px) {
    .category-nav {
        width: 30%;
    }
    
    .product-display {
        width: 70%;
    }
    
    .product-item {
        width: calc(33.333% - 1rem);
    }
}

@media (max-width: 480px) {
    .category-nav li {
        font-size: 1.8rem;
    }
    
    .product-item {
        width: calc(33.333% - 1rem);
    }
}

</style>
    <!-- 头部导航 -->
    <header class="header">
        <div class="header-left">
            <button class="back-btn">&lt;</button>
            <button class="menu-btn">☰</button>
        </div>
        <h1 class="title">分类</h1>
    </header>
    
    <!-- 主体内容 -->
    <div class="main-content">
        <!-- 左侧分类导航 -->
        <aside class="category-nav">
            <ul>
                <li class="active"><a href="#" data-href="/category/shoes-bags">服饰鞋包</a></li>
                <li><a href="#" data-href="/category/care-cleaning">个护清洁</a></li>
                <li><a href="#" data-href="/category/domestic-life">居家生活</a></li>
                <li><a href="#" data-href="/category/digital-home-appliances">数码家电</a></li>
                <li><a href="#" data-href="/category/sports-travel">运动旅行</a></li>
            </ul>
        </aside>
    
        <!-- 右侧商品展示 -->
        <section class="product-display">
        
        </section>
    </div>
    
    `
}

export function afterRender() {
    var ul = document.querySelector("ul");
    var section = document.querySelector("section");

    var categoryNavUl = document.querySelector(".category-nav > ul");

    categoryNavUl.addEventListener("click", function (e) {
        if(e.target.tagName === "A"){
            navigate(e.target.getAttribute("data-href"));
        }
    })

    async function navigate(hash = "/category/shoes-bags"){
        var module;
        switch (hash){
            case '/category/shoes-bags':
                module = await import("./category/shoes-bags.js");
                break;
            case '/category/care-cleaning':
                module = await import("./category/care-cleaning.js");
                break;
            case '/category/domestic-life':
                module = await import("./category/domestic-life.js");
                break;
            case '/category/digital-home-appliances':
                module = await import("./category/digital-home-appliances.js");
                break;
            case '/category/sports-travel':
                module = await import("./category/sports-travel.js");
                break;
        }

        if(module && module.Render){
            var html = module.Render();

            section.innerHTML = html;

            if(module.afterRender){
                module.afterRender();
            }
        }
    }

    navigate(); //首次加载
    window.addEventListener("hashchange", navigate); //hash变化加载

    // 点击左边导航栏
    ul.addEventListener("click", function (e) {
        if (e.target.nodeName === "A") {
            e.preventDefault();
            document.querySelector('.active').classList.remove('active');
            e.target.classList.add("active");
        }
    })

}

